package com.tsingxiao.codegenerate.api.controller;

import com.tsingxiao.codegenerate.common.dto.ResultDto;
import com.tsingxiao.codegenerate.pojo.Demo;
import com.tsingxiao.codegenerate.service.DemoService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author qingchang.tang
 * @date 2020/5/25 16:48
 */
@RestController
@RequestMapping("/demo")
@Scope("prototype")
@AllArgsConstructor
public class DemoController {

    private final DemoService demoService;

    @PostMapping(value = "/save")
    public ResultDto<Integer> save(@RequestBody Demo o) {
        int data = demoService.save(o);
        return new ResultDto<>(data);
    }

    @GetMapping("/list")
    public ResultDto<List<Demo>> list() {
        List<Demo> data = demoService.list();
        return new ResultDto<>(data);
    }
}
